package com.netty.chapter10;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.logging.LoggingHandler;
import lombok.extern.slf4j.Slf4j;

import java.net.InetSocketAddress;

@Slf4j
public class ConnectTimeOutTest {
    public static void main(String[] args) {
        NioEventLoopGroup group = new NioEventLoopGroup();
        Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(group)
                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS,300)
                .channel(NioSocketChannel.class)
                .handler(new LoggingHandler());
        ChannelFuture future = bootstrap.connect(new InetSocketAddress("localhost", 8080));
        try {
            future.sync().channel().closeFuture().sync();
        } catch (InterruptedException e) {
            group.shutdownGracefully();
            e.printStackTrace();
            log.debug("timeout");
        }
    }
}
